import type { ListPageModel, PageModel, SelectionModel } from '@/api/model/CommonModel';
import type { VenueModel } from '@/api/model/venueModel';
import { request } from '@/utils/request';

const Api = {
  CreateVenue: '/venue/create',
  GetVenue: '/venue/getList',
  DeleteVenue: '/venue/delete',
  GetVenueInfos: '/venue/venueInfo',
  UpdateVenue: '/venue/update',
  GetVenueSelectList: '/venue/selectList',
};

/** 创建用户 */
export const createVenue = (data: Partial<VenueModel>) => {
  return request.post<boolean>({
    url: Api.CreateVenue,
    data,
  });
};

interface IGetVenueParams extends PageModel {
  venueName?: string;
  address?: string;
}

/** 获取用户列表 */
export const getVenueList = (params: IGetVenueParams) => {
  return request.get<ListPageModel<VenueModel>>({
    url: Api.GetVenue,
    params,
    withCredentials: true,
  });
};

/** 删除场馆 */
export const deleteVenue = (venueId: string) => {
  return request.delete<ListPageModel<VenueModel>>({
    url: Api.DeleteVenue,
    params: { venueId },
  });
};

/** 根据venueId获取场馆信息 */
export const getVenueInfosById = (venueId: string) => {
  return request.get<Partial<VenueModel>>({
    url: Api.GetVenueInfos,
    params: { venueId },
  });
};

/** 更新场馆信息 */
export const UpdateVenue = (venue: Partial<VenueModel>) => {
  return request.put<boolean>({
    url: Api.UpdateVenue,
    params: { ...venue },
  });
};

/** 根据条件获取场馆列表 */
export const getVenueSelectList = (venue: IGetVenueParams) => {
  return request.get<ListPageModel<SelectionModel[]>>({
    url: Api.GetVenueSelectList,
    params: { ...venue },
  });
};
